package com.splic.product.service.impl;

import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.splic.product.mapper.ProvinceMapper;
import com.splic.product.domain.Province;
import com.splic.product.service.ProvinceService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 省份设置Service业务层处理
 * 
 * @author singe
 * @date 2022-03-08
 */
@Service
public class ProvinceServiceImpl implements ProvinceService
{
    @Autowired
    private ProvinceMapper provinceMapper;

    /**
     * 查询省份设置
     * 
     * @param provinceId 省份设置主键
     * @return 省份设置
     */
    @Override
    public Province selectProvinceByProvinceId(Long provinceId)
    {
        return provinceMapper.selectProvinceByProvinceId(provinceId);
    }

    /**
     * 查询省份设置列表
     * 
     * @param province 省份设置
     * @return 省份设置
     */
    @Override
    public List<Province> selectPageList(Province province)
    {
        return provinceMapper.selectProvinceList(province);
    }

    /**
     * 查询省份设置列表
     *
     * @param province 省份设置
     * @return 省份设置
     */
    @Override
    public List<Province> selectProvinceList(Province province)
    {
        return provinceMapper.selectProvinceList(province);
    }

    /**
     * 新增省份设置
     * 
     * @param province 省份设置
     * @return 结果
     */
    @Override
    public int insert(Province province)
    {
        return provinceMapper.insert(province);
    }

    /**
     * 修改省份设置
     * 
     * @param province 省份设置
     * @return 结果
     */
    @Override
    public int update(Province province)
    {
        return provinceMapper.update(province);
    }


    /**
     * 删除省份设置信息
     * 
     * @param provinceId 省份设置主键
     * @return 结果
     */
    @Override
    public int deleteById(Long provinceId)
    {
        return provinceMapper.deleteById(provinceId);
    }
    /**
     * 修改省份设置
     *
     * @param province 省份设置信息
     * @return 结果
     */
    @Override
    @Transactional
    public int saveOrUpdate(Province province)
    {
        if(province.getId() != null){
            province.setUpdateTime(new Date());
            return provinceMapper.update(province);
        }else{
            province.setCreateTime(new Date());
            return provinceMapper.insert(province);
        }
    }

    /*@Autowired
    private CityService cityServiceImpl;
    @Autowired
    private CountyService countyServiceImpl;

    @Override
    public List<ProvinceJson> selectProvinceJsonList() {
        List<ProvinceJson> provinceJsonList = Lists.newArrayList();
        List<Province> provinceList = selectProvinceList(null);
        ProvinceJson provinceJson = null;
        ProvinceJson.CityJson cityJson = null;
        ProvinceJson.CityJson.CountyJson countyJson = null;
        City cityQuery = new City();
        County countyQuery = new County();
        if(CollectionUtils.isNotEmpty(provinceList)){
            for(Province province:provinceList){
                provinceJson = new ProvinceJson();
                provinceJson.setCode(province.getProvinceCode());
                provinceJson.setName(province.getProvinceName());

                cityQuery.setProvinceCode(province.getProvinceCode());
                List<City> cityList = cityServiceImpl.selectCityList(cityQuery);

                for(City city:cityList){
                    cityJson = new ProvinceJson.CityJson();
                    cityJson.setCode(city.getCityCode());
                    cityJson.setName(city.getCityName());
                    provinceJson.getCity().add(cityJson);

                    countyQuery.setCityCode(city.getCityCode());
                    List<County> countyList = countyServiceImpl.selectCountyList(countyQuery);
                    for(County county:countyList){
                        countyJson = new ProvinceJson.CityJson.CountyJson();
                        countyJson.setCode(county.getAreaCode());
                        countyJson.setName(county.getAreaName());
                        cityJson.getArea().add(countyJson);
                    }
                }
                provinceJsonList.add(provinceJson);
            }
        }
        return provinceJsonList;
    }*/
}
